﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.WordDeleteRow
{
    public class WordDeleteRowController : Controller
    {
        private readonly IWebHostEnvironment _webHostEnvironment;
        public WordDeleteRowController(IWebHostEnvironment webHostEnvironment)
        {
            _webHostEnvironment = webHostEnvironment;
        }
        public IActionResult Word()
        {
            ViewBag.FilePath = _webHostEnvironment.WebRootPath + "\\WordDeleteRow\\doc\\test_table.doc"; 

            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            PageOfficeNetCore.Word.WordDocumentWriter doc = new PageOfficeNetCore.Word.WordDocumentWriter();
            PageOfficeNetCore.Word.WordTableWriter table1 = doc.OpenDataRegion("PO_table").OpenTable(1);
            PageOfficeNetCore.Word.WordCellWriter cell = table1.OpenCellRC(2, 1);
            //删除坐标为(2,1)的单元格所在行
            table1.RemoveRowAt(cell);

            poCtrl.SetWriter(doc);
            //打开Word文档
            poCtrl.WebOpen("doc/test_table.doc", PageOfficeNetCore.OpenModeType.docNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }
    }
}